home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / os2 / wuz11a.zip / KILL-DIR.CMD < prev    next >
OS/2 REXX Batch file  |  1993-12-08  |  3KB  |  109 lines

  1. /* Remove all files from directory and remove directory */
  2. /* (c) Copyright 1993 Scott Maxwell.            */
  3.  
  4. arg Name Options
  5.  
  6. if (Left(Name,1) = '/') | (Left(Name,1) = '-') then do
  7.   swap = Name
  8.   Name = Options
  9.   Options = swap
  10.   end
  11.  
  12. if (Options \= '') & (Options \= '/X') & (Options \= '-X') then signal ShowUsage
  13. if Name = '' then signal ShowUsage
  14.  
  15. dir.1 = Directory()
  16. if SubStr(Name,2,1) = ':' then do
  17.   if (length(Name) = 2) | ((length(Name) = 3) & (Right(Name,1) = '\')) then do
  18.     say "What?! I refuse to delete the root of any drive."
  19.     exit(1)
  20.   end
  21.   if SubStr(Name,3,1) = '.' then do
  22.     say "I refuse to kill relatives! It's too dangerous."
  23.     exit(1)
  24.   end
  25.   dir.2 = Directory(Left(Name,2))
  26.   if dir.2 = '\' then do
  27.     say "No drive" Left(Name,2)
  28.     exit(1)
  29.   end
  30. end
  31. else do
  32.   if Left(Name,1) = '.' then do
  33.     say "I refuse to kill relatives! It's too dangerous."
  34.     exit(1)
  35.   end
  36.   if Name = '\' then do
  37.     say "What?! I refuse to delete the root of any drive."
  38.     exit(1)
  39.   end
  40.   dir.2 = dir.1
  41. end
  42.  
  43. fName = directory(Name)
  44. if fName = '\' then do
  45.   say Name": directory not found"
  46.   exit(1)
  47. end
  48.  
  49. Call Directory dir.2
  50. Call Directory dir.1
  51.  
  52. Name = fName
  53.  
  54.  
  55. CALL RxFuncAdd 'SysRmDir','RexxUtil','SysRmDir'
  56. if Check4OS2()=1 THEN
  57.   '@del /qsxyz' Name'* 2> nul'
  58. else do
  59.   CALL RxFuncAdd 'SysFileTree','RexxUtil','SysFileTree'
  60.   CALL RxFuncAdd 'SysFileDelete','RexxUtil','SysFileDelete'
  61.   Call SysFileTree Name'*.*','dir','FS','*****','-*---'
  62.  
  63.   do i=1 to dir.0
  64.     parse VAR dir.i . . . . fname
  65.     Call 'SysFileDelete' STRIP(fname)
  66.   end
  67.  
  68.   Call SysFileTree Name,'dir','SD','*****','-*---'
  69.   do i=1 to dir.0
  70.     parse VAR dir.i . . . . fname
  71.     Call 'SysRmDir' STRIP(fname)
  72.   end
  73.   Call SysRmDir Left(Name,LENGTH(Name)-1)
  74. end
  75.  
  76. if Length(CharIn(Name'zclr.cmd',1,1)) = 1 then do
  77.   '@attrib -h' Name'zclr.cmd > nul 2> nul'
  78.   '@del' Name'zclr.cmd > nul 2> nul'
  79.   if SysRmDir(Left(Name,LENGTH(Name)-1)) \= 0 then do
  80.     say "Can't remove" Name
  81.     exit
  82.   end
  83. end
  84.  
  85. if Right(Options,1) = 'X' then
  86.    '@exit'
  87. exit(0)
  88.  
  89.  
  90. Check4OS2: procedure
  91.   '@set is4os2=%_4ver'
  92.   return DATATYPE(VALUE(is4os2,,OS2ENVIRONMENT),'N')
  93.  
  94. ShowUsage:
  95.   say "USAGE: Kill-Dir [-x] directory-name"
  96.   say "  Deletes the specified directory and all of its contents"
  97.   say "  If -x option is specified, the OS/2 window is closed"
  98.   exit
  99.  
  100. Directory: procedure
  101.   arg Name
  102.   if Length(Name) > 3 then
  103.     if Right(Name,1) = '\' then
  104.       Name = Left(Name,LENGTH(Name)-1)
  105.   n = 'DIRECTORY'(Name)
  106.   if Right(n,1) \= '\' then
  107.     n = n'\'
  108.   return n
  109.